<template>
  <a-modal
    title="查看产品型号"
    width="80%"
    :visible="visible"
    :confirmLoading="confirmLoading"
    :footer="null"
    @cancel="handleCancel"
  >
    <a-spin :spinning="confirmLoading">
      <a-form :form="form">
        <a-form-item
          label="型号编码"
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
        >
          <a-input readOnly placeholder="型号编码" v-decorator="['code', {rules: [{required: true, message: '型号编码！'}]}]" />
        </a-form-item>
        <a-form-item v-show="false"><a-input v-decorator="['id']" /></a-form-item>
        <a-form-item
          label="型号名称"
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
        >
          <a-input readOnly placeholder="型号名称" v-decorator="['name', {rules: [{required: true, message: '型号名称！'}]}]" />
        </a-form-item>
        <a-form-item
          label="产品名称"
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
        >
          <a-select :open="false" style="width: 100%" placeholder="请选择产品" v-decorator="['proId', {rules: [{ required: false, message: '产品名称！' }]}]">
            <a-select-option disabled="true" v-for="(item,index) in list.proModeList" :key="index" :value="item.id">{{ item.name }}</a-select-option>
          </a-select>
        </a-form-item>
        <a-form-item
          label="库存单位"
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
        >
          <a-select :open="false" style="width: 100%" placeholder="请选择库存单位" v-decorator="['unit', {rules: [{ required: false, message: '库存单位！' }]}]">
            <a-select-option disabled="true" v-for="(item,index) in unitData" :key="index" :value="item.code">{{ item.name }}</a-select-option>
          </a-select>
        </a-form-item>
        <a-form-item
          label="备注"
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
        >
          <a-textarea readOnly placeholder="请输入备注" v-decorator="['remarks']" :auto-size="{ minRows: 3, maxRows: 6 }"/>
        </a-form-item>
      </a-form>
    </a-spin>
  </a-modal>
</template>

<script>
  import { proList } from '@/api/modular/main/pro/proManage'

  export default {
    data () {
      return {
        list: {
          proModeList: []
        },
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 }
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 15 }
        },
        unitData: [],
        visible: false,
        confirmLoading: false,
        form: this.$form.createForm(this)
      }
    },
    methods: {
      // 初始化方法
      open (record) {
        this.visible = true
        this.unitData = this.$options.filters['dictData']('unit')
        proList().then(res => {
          this.list.proModeList = res.data
        })
        setTimeout(() => {
          this.form.setFieldsValue(
            {
              code: record.code,
              id: record.id,
              name: record.name,
              proId: record.proId,
              remarks: record.remarks,
              unit: record.unit
            }
          )
        }, 100)
      },
      handleCancel () {
        this.form.resetFields()
        this.visible = false
      }
    }
  }
</script>
